package cn.yunyichina.provider.reservation.service.impl;

import cn.yunyichina.provider.iface.entity.common.Response;
import cn.yunyichina.provider.reservation.dao.DeptDao;
import cn.yunyichina.provider.reservation.entity.Dept;
import cn.yunyichina.provider.reservation.service.DeptService;
import cn.yunyichina.utils.convert.JsonUtils;
import com.alibaba.fastjson.JSON;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.UUID;

/**
 * Created by Lullaby on 2016/8/29.
 */
@Service
public class DeptServiceImpl implements DeptService {

    @Resource
    private DeptDao deptDao;

    public Response listDept(String params) {
        Response response = new Response();
        Dept dept = JsonUtils.parseObject(params, Dept.class);
        List<Dept> depts = deptDao.select(dept);
        response.setResult(JSON.toJSONString(depts));
        return response;
    }

    public Response createDept(String params) {
        Response response = new Response();
        Map<String, String> map = JSON.parseObject(params, Map.class);
        Dept dept = new Dept();
        dept.setId(map.get("id"));
        dept.setMechanismId(map.get("mechanism_id"));
        dept.setName(map.get("name"));
        dept.setCode(map.get("code"));
        dept.setAddress(map.get("address"));
        dept.setCreateUser(map.get("create_user"));
        deptDao.insert(dept);
        return response;
    }

    public Response getDept(String params) {
        Response response = new Response();
        Map<String, String> map = JSON.parseObject(params, Map.class);
        String id = map.get("id");
        Dept dept = deptDao.selectById(id);
        response.setResult(JSON.toJSONString(dept));
        return response;
    }

    public Response updateDept(String params) {
        Response response = new Response();
        Map<String, String> map = JSON.parseObject(params, Map.class);
        Dept dept = new Dept();
        dept.setId(map.get("id"));
        dept.setName(map.get("name"));
        dept.setCode(map.get("code"));
        dept.setAddress(map.get("address"));
        deptDao.update(dept);
        return response;
    }

    public Response deleteDept(String params) {
        Response response = new Response();
        Map<String, String> map = JSON.parseObject(params, Map.class);
        Dept dept = new Dept();
        dept.setId(map.get("id"));
        deptDao.delete(dept);
        return response;
    }

}
